package com.qianye.service.impl;


import com.qianye.entity.RobotStrategyRelation;
import com.qianye.mapper.RobotStrategyRelationDao;
import com.qianye.service.RobotStrategyRelationCoreService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (RobotStrategyRelation)表服务实现类
 *
 * @author makejava
 * @since 2024-09-16 23:46:17
 */
@Service("robotStrategyRelationCoreService")
public class RobotStrategyRelationCoreServiceImpl implements RobotStrategyRelationCoreService {
    @Resource
    private RobotStrategyRelationDao robotStrategyRelationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RobotStrategyRelation queryById(Long id) {
        return this.robotStrategyRelationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param robotStrategyRelation 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RobotStrategyRelation> queryByPage(RobotStrategyRelation robotStrategyRelation, PageRequest pageRequest) {
        long total = this.robotStrategyRelationDao.count(robotStrategyRelation);
        return new PageImpl<>(this.robotStrategyRelationDao.queryAllByLimit(robotStrategyRelation, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param robotStrategyRelation 实例对象
     * @return 实例对象
     */
    @Override
    public RobotStrategyRelation insert(RobotStrategyRelation robotStrategyRelation) {
        this.robotStrategyRelationDao.insert(robotStrategyRelation);
        return robotStrategyRelation;
    }

    /**
     * 修改数据
     *
     * @param robotStrategyRelation 实例对象
     * @return 实例对象
     */
    @Override
    public RobotStrategyRelation update(RobotStrategyRelation robotStrategyRelation) {
        this.robotStrategyRelationDao.update(robotStrategyRelation);
        return this.queryById(robotStrategyRelation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.robotStrategyRelationDao.deleteById(id) > 0;
    }
}
